package tools;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Constants {
		
	public static final String PROPERTY_FILE_PATH = "./config/properties.xml";

	public static final String Time_template = "yyyy-MM-dd HH:mm:ss";
	public static final String Time_template_MIN = "yyyy-MM-dd HH:mm";
	public static final String Time_template_HOUR = "yyyy-MM-dd HH";
	public static final String Time_template_LONG = "yyyyMMddHHmm";
		
	//DB string
	public static final String Table_mininfo = "mininfo";
	public static final String Table_hourinfo = "hourinfo";
	public static final String Table_ServerLog = "ServerLog";
	
	public static final String Field_time = "Time";
	public static final String Field_ServerName = "ServerName";
	public static final String Field_sOk = "sOK";
	public static final String Field_sError = "sERROR";
	public static final String Field_sTimeout = "sTIMEOUT";
	public static final String Field_host = "Host";
	public static final String Field_AVGOk = "AVGOK";
	public static final String Field_AVGError = "AVGERROR";
	public static final String Field_AVGTimeout = "AVGTIMEOUT";
		
	public static final String SQL_SerchLastestTime = "SELECT ? FROM ? WHERE ? = '?' ORDER BY ? DESC LIMIT 1";
	public static final String SQL_InsertTable = "INSERT INTO ? (?, ?, ?, ?, ?, ?) VALUES ('?', '?','?', '?','?','?') ";
	public static final String SQL_SerchLastMinute = " SELECT Time ,SUM(sOK),AVG(sOK), SUM(sERROR),AVG(sERROR)," +
											" SUM(sTIMEOUT), AVG(sTIMEOUT) FROM ServerLog WHERE " +
														" Host = '?' AND Time >= '?' - INTERVAL ? ? ";
	
	public static final String SQL_SerchTimeRange_Server = " SELECT SUM(sOK),AVG(sOK), SUM(sERROR),AVG(sERROR)," +
											" SUM(sTIMEOUT), AVG(sTIMEOUT) FROM ServerLog WHERE " +
												" Host = '?' AND Time >= '?' AND Time <= '?' and ServerName = '?' ";
	public static final String SQL_SerchTimeRange = " SELECT SUM(sOK),AVG(sOK), SUM(sERROR),AVG(sERROR)," +
											" SUM(sTIMEOUT), AVG(sTIMEOUT) FROM ServerLog WHERE " +
												" Host = '?' AND Time >= '?' AND Time <= '?' ";
	public static final String SQL_SerchFieldList = "SELECT DISTINCT ? FROM ServerLog WHERE Host = '?' ";
	
	public static final String SQL_DeleteData = "DELETE FROM ServerLog WHERE Host = '?' ";
	
	public static final String SQL_SerchLastestData = "SELECT Time,sOK,sERROR, sTIMEOUT FROM ServerLog " +
													" WHERE Host = '?' AND ServerName = '?' " +
													" ORDER BY Time DESC LIMIT 1 ";

	
	
	
	
	
	// Date to String：  
	public static String DatetoString(Date someDate, String template) {  
		    if(someDate == null)		
		    	return "";  
		    SimpleDateFormat formatter = new SimpleDateFormat(template);  
		    String dateString = formatter.format(someDate);  
		    return dateString;  
	}    
		  
	// String to Date 用template限制时间字符串的格式，如yyyy-MM-dd HH:mm:ss  
	public static Date StringtoDate(String input, String template) throws ParseException {  
	      DateFormat df = new SimpleDateFormat(template);  
	      Date date = new Date();  
	        
	          date = df.parse(input);  
	    
	      return date;  
	}   




}
